package com.lc.boxuegu.S_isSymmetric;

/**
 * @author zhaiyj
 * @date 2025/6/12 20:50
 */
public class Solution {

    public boolean isSymmetric(TreeNode root) {
        return isSameTree(root.left, root.right);
    }

    public boolean isSameTree(TreeNode p, TreeNode q){
        if(p == null || q == null){
            return p == q;
        }

        return p.val == q.val && isSameTree(p.left, q.right)  && isSameTree(p.right, q.left);
    }




    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }


}
